/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package util.www.servlet;

/**
 *
 * @author Rdelacruz
 */
public class HandlerContext {
        String path;
        public String[] pathseg;
        public int idx;
        boolean done;
        HttpMethod meth;        
        
        public HandlerContext(String path, HttpMethod meth) { 
                setPath(path);
                setHttpMethod(meth);
        }
        
        public void setHttpMethod(HttpMethod meth) {
                this.meth = meth;
        }

        public HttpMethod getHttpMethod() {
                return meth;
        }

        public void setPath(String path) {
                this.path = path;
                this.pathseg = null;
                idx = 0;
                done = false;
                pathseg = split(path, "/");
        }
        
        static String[] split(String s, String sep) {  
            return null;
        }

        String getPathSeg(boolean advance) {
                if (pathseg==null) return null;
                if (idx>=pathseg.length) return null;
                String s = pathseg[idx];
                if (advance && idx<=pathseg.length) idx++;
                return s;
        }               

        String getPathSeg() { return getPathSeg(false); }       
                
        String nextPathSeg() { return getPathSeg(true); }
        String prevPathSeg() {
                if (pathseg==null) return null;
                if (idx-1<0) return null;
                return pathseg[idx-1];          
        }
        
        void setDone(boolean done) { this.done = done; }        
        boolean isDone() { return done; }    
}
